package com.stox.services.indicator.model;

import java.util.List;

import com.stox.services.indicator.model.config.BarValueAwareConfig;
import com.stox.services.indicator.model.intf.Indicator;
import com.stox.shared.model.Bar;
import com.stox.shared.model.enumeration.BarValue;
import com.stox.shared.util.BarUtil;

public abstract class AbstractIndicator<OUT, CONFIG> implements Indicator<OUT, CONFIG> {

	public OUT getValue(CONFIG configuration, List<Bar> in, int index){
		return getValue(configuration, asDoubleArray(configuration, in), index);
	}

	public OUT[] getValues(CONFIG configuration, List<Bar> in) {
		return getValues(configuration, asDoubleArray(configuration, in));
	}
	
	private Double[] asDoubleArray(CONFIG configuration, List<Bar> in){
		BarValue barValue = BarValue.CLOSE;
		if(configuration instanceof BarValueAwareConfig){
			BarValueAwareConfig barValueAwareConfig = (BarValueAwareConfig)configuration;
			barValue = barValueAwareConfig.getBarValue();
		}
		return BarUtil.values(in, barValue);
	}
	
}
